<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=GBK">
    <title>登陆页面</title>
</head>
<body>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src=" <%=request.getContextPath()%>/js/jquery.js"></script>
<script>
function onLogin() {
$.ajax({
//几个参数需要注意一下
type: "POST",//方法类型
dataType: "text",//预期服务器返回的数据类型
url: "<%=request.getContextPath()%>/login",//url
data: $('#loginForm').serialize(),
success: function (result) {
alert("result"+result)
},
error: function () {
alert("异常！");
}
});
}
</script>
<form method="POST" id="loginForm" action="<%=request.getContextPath()%>/login">
    用户名：<input type="text" name="username"></br>
    密码：<input type="password" name="password"></br>
    <input type="submit" value="登陆" onclick="onLogin()">
    <input type="button" value="注册" onclick="location.href='/addUser.jsp'">
    <input type="reset" value="重置">
</form>
</body>
</html>